<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/8
 * Time: 16:34
 */

$username = $_POST['username'];
$oldPsd = $_POST['oldPsd'];
$newPad = $_POST['$newPad'];

$key = $_COOKIE['userkey'];

//开启session
session_start();
if (!isset($_SESSION[$key]))
{
    echo '你尚未登录,<a href="login.php">请登入</a>';
    die;
}else{
    if ($key==md5($username.$oldPsd))
    {
        if ($newPad==$oldPsd)
        {
            exit('旧密码与新密码不可相同!!!');
        }
        $key = md5($username.$newPad);
        setcookie('userkey',$key,time()+24*3600);
        $_SESSION[$key]=[
            'username'=>$username,
            'psd'=>$newPad
        ];
        echo '<h1>修改成功</h1>';
    }else{
        echo '旧密码或用户名输入错误!!!!';
    }
}